package com.jokerpan.project.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jokerpan.project.commons.ActionResult;
import com.jokerpan.project.commons.PaginationBuilder;
import com.jokerpan.project.commons.ResultBuilder;
import com.jokerpan.project.entity.UsersRole;
import com.jokerpan.project.mapper.RolesMapper;
import com.jokerpan.project.service.RolesService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author jokerpan
 */
@Service("rolesService")
public class RolesServiceImpl implements RolesService {
    @Resource
    RolesMapper rolesMapper;


    @Override
    public Map<String, Object> queryList(UsersRole usersRole) {
        Page<Object> page = PageHelper.startPage(usersRole.getCurrentPage(), usersRole.getPageSize());
        List<UsersRole> resultList = this.rolesMapper.queryList(usersRole);
        return PaginationBuilder.buildResult(resultList, page.getTotal(), usersRole.getCurrentPage(), usersRole.getPageSize());
    }

    @Override
    public List<UsersRole> queryById(Integer id) {
        return rolesMapper.queryById(id);
    }

    @Override
    public Boolean add(UsersRole usersRole) {
        return rolesMapper.add(usersRole) > 0;
    }

    @Override
    public ActionResult update(UsersRole usersRole) {
        if (rolesMapper.update(usersRole) > 0){
            return ResultBuilder.buildActionSuccess();
        }else {
            return ResultBuilder.buildActionFailed();
        }
    }

    @Override
    public ActionResult deleteById(Integer id) {
        if (rolesMapper.deleteById(id) > 0){
            return ResultBuilder.buildActionSuccess();
        }else {
            return ResultBuilder.buildActionFailed();
        }
    }
}
